﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Data.SqlTypes;
using System.Collections.Generic;
using System.Web.Configuration;

using AjaxControlToolkit;
using TempEmployees.BLL;

namespace TempEmployees.Web
{
    public static class GUIServices
    {
        // page url's
        public static readonly string PAGE_NEW_ASSIGNMENT = "~/NewAssignment.aspx";
        public static readonly string PAGE_SEARCH_EMPLOYEES = "~/SearchEmployees.aspx";
        public static readonly string PAGE_SEARCH_ASSIGNMENTS = "~/SearchAssignments.aspx";
        public static readonly string PAGE_UPDATE_EMPLOYEE = "~/UpdateEmployee.aspx";
        public static readonly string PAGE_UPDATE_ASSIGNMENT = "~/UpdateAssignment.aspx";
        public static readonly string PAGE_LOGIN = "~/Login.aspx";
        public static readonly string PAGE_ACCOUNTANT = "~/AcountentForms/Accountant.aspx";
        public static readonly string PAGE_ERROR = "~/ErrorPage.aspx";
        public static readonly string PAGE_BUDGETS = "~/AccountentForms/Budgets.aspx";
        public static readonly string PAGE_PRODUCE_FORMS = "~/SecretaryForms/ProduceForms.aspx";

        // error messages
        public static readonly string MESSAGE_ERR_VALIDATION = WebConfigData.MESSAGE_ERR_VALIDATION;
        public static readonly string MESSAGE_ERR_REQUIRED = WebConfigData.MESSAGE_ERR_REQUIRED;
     
        public static string BuildErrorMessage(string error, string issue)
        {
            List<string> errors = new List<string>(new string[] {error});
            return BuildErrorMessage(errors, issue);
        }

        public static string BuildErrorMessage(List<string> errors, string issue)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string error in errors)
            {
                if (sb.Length == 0)
                {
                    sb.Append(issue);
                    sb.Append(error);
                }
                else
                {
                    sb.Append(string.Format(", {0}", error));
                }
            }
            return sb.ToString();
        }

        public static void SetErrorPanel(Panel panel, Label errorLabel, List<string> errors, string issue)
        {
            if (errors.Count == 0) panel.Visible = false;
            else
            {
                panel.Visible = true;
                errorLabel.Text = BuildErrorMessage(errors, issue);
            }
        }
    }
}


